<html>
<head><meta charset="utf-8"><title>f32_runtime lang item? · t-libs · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/index.html">t-libs</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/f32_runtime.20lang.20item.3F.html">f32_runtime lang item?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="214109049"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/f32_runtime%20lang%20item%3F/near/214109049" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bstrie <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/f32_runtime.20lang.20item.3F.html#214109049">(Oct 21 2020 at 20:18)</a>:</h4>
<p>I'm poking around in the f32 module and noticed that unlike ints, floats have some inherent impls defined in libcore and others in libstd, the former with the "f32" lang item and the latter with "f32_runtime". I couldn't find docs describing what the purpose of this split is. if it's portability concerns, then I still don't see why those would prevent these from being defined in libcore?</p>



<a name="214110916"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/f32_runtime%20lang%20item%3F/near/214110916" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/f32_runtime.20lang.20item.3F.html#214110916">(Oct 21 2020 at 20:33)</a>:</h4>
<p>The std ones link to libm I believe</p>



<a name="214113443"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/f32_runtime%20lang%20item%3F/near/214113443" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bstrie <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/f32_runtime.20lang.20item.3F.html#214113443">(Oct 21 2020 at 20:55)</a>:</h4>
<p>interesting, is libm what "cmath" refers to in std/f32.rs? because I see some of the std/f32 impls delegate to intrinsics::foo, and others to cmath::bar. anything that's intrinsic is something provided by LLVM, correct? any reason that those methods (e.g. floor, trunc) couldn't be moved to libcore then?</p>



<a name="214117663"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/f32_runtime%20lang%20item%3F/near/214117663" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/f32_runtime.20lang.20item.3F.html#214117663">(Oct 21 2020 at 21:33)</a>:</h4>
<p>IIRC those intrinsics will also lower to <code>libm</code> if there's no architectural support</p>



<a name="214127574"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/f32_runtime%20lang%20item%3F/near/214127574" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/f32_runtime.20lang.20item.3F.html#214127574">(Oct 21 2020 at 23:31)</a>:</h4>
<p>some of them should be pretty trivial to implement (e.g. <code>f32::trunc</code>), could we add those to compiler-builtins or something?</p>



<a name="214130109"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/f32_runtime%20lang%20item%3F/near/214130109" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/f32_runtime.20lang.20item.3F.html#214130109">(Oct 22 2020 at 00:06)</a>:</h4>
<p>In general there are implementations for a lot of this stuff in <a href="https://github.com/rust-lang/libm">https://github.com/rust-lang/libm</a>, although it's very clear the code is optimized for readability over performance... (whenever i dip in there are pretty clear optimizations i see, but the testing setup is so convoluted (requires building on linux with musl) that i've never really wanted to PR it — it's also not 100% clear they'd be accepted given the statement that it's just a port of musl's impl)</p>



<a name="214133439"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/f32_runtime%20lang%20item%3F/near/214133439" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bstrie <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/f32_runtime.20lang.20item.3F.html#214133439">(Oct 22 2020 at 01:02)</a>:</h4>
<p>I think everyone would agree that having any implementation in core at all is preferable to having no implementation, yes? just so long as it's not penalizing libstd. is there cfg magic we could do to pull in the rust libm when using the core profile? looks like there's already shenanigans going on in order to allow inherent impls on floats in two crates, so I don't imagine this would be out of the question (and doesn't panic! already do something like this, with different implementations in core and std?)</p>



<a name="214140086"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/f32_runtime%20lang%20item%3F/near/214140086" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/f32_runtime.20lang.20item.3F.html#214140086">(Oct 22 2020 at 03:24)</a>:</h4>
<p>I think it would be unfortunate if getting decent perf required std, but I guess it's better than nothing. I mean, this has been a performance footgun in the past for people already — some crates (nalgebra I think is one) have no_std variants that depend on libm, and get way worse performance if that mode is on (usually because someone did default-feature=false).</p>
<p>It also seems tricky to set up, but I guess it already needs a lang item so its not out of the question)</p>



<a name="214140802"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/f32_runtime%20lang%20item%3F/near/214140802" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/f32_runtime.20lang.20item.3F.html#214140802">(Oct 22 2020 at 03:45)</a>:</h4>
<p>num-traits has some implemented in <code>FloatCore</code> which do forward to <code>std</code> when possible</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>